#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdbool.h>
struct TreeNode {
    int val;
    struct TreeNode* left;
    struct TreeNode* right;
    
};
int height(struct TreeNode* root)
{
    if (root == NULL)
        return 0;
    else return fmax(height(root->right), height(root->left)) + 1;
}


bool isBalanced(struct TreeNode* root) {
    if (root == NULL)
        return true;
    else return fabs(height(root->right) - height(root->left)) <= 1 && isBalanced(root->right) && isBalanced(root->left);
}